package com.zbkj.service.service.device;

import com.baomidou.mybatisplus.extension.service.IService;
import com.zbkj.common.model.device.MqttConfig;
import com.zbkj.common.request.MonitorControlLightRequest;
import com.zbkj.common.request.device.DeviceRequest;
import org.eclipse.paho.client.mqttv3.MqttException;

import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.Map;

/**
 * MQTT配置服务接口
 * +----------------------------------------------------------------------
 * | Author: xiaolic
 * +----------------------------------------------------------------------
 */
public interface MqttConfigService extends IService<MqttConfig> {

    /**
     * 获取默认的MQTT配置
     * @return MQTT配置信息
     */
    MqttConfig getDefaultConfig();

    /**
     * 根据设备ID获取MQTT配置
     * @param deviceId 设备ID
     * @return MQTT配置信息
     */
    MqttConfig getConfigByDeviceId(Long deviceId);

    MqttConfig getConfigByDevice(DeviceRequest request) throws Exception;

    /**
     * 将MQTT配置信息格式化为设备所需的返回格式
     * @param config MQTT配置信息
     * @return 格式化后的字符串
     */
    String formatMqttConfigResponse(MqttConfig config);


    void publish(String clientId, String topic, String msg) throws MqttException, NoSuchAlgorithmException, InvalidKeyException;

    /**
     * 推送MQTT消息
     * @param requestVo
     * @throws MqttException
     * @throws NoSuchAlgorithmException
     * @throws InvalidKeyException
     * @throws Exception
     */
    void publishControlCmd(MonitorControlLightRequest requestVo) throws MqttException, NoSuchAlgorithmException, InvalidKeyException, Exception;

}
